class Solution:
    def minimumJumps(self, forbidden: list, a: int, b: int, x: int) -> int:
        if x == 0:
            return 0
        queue = [(0, False)]
        level = 0
        visited = set()
        visited.add(0)
        forbidden = set(forbidden)
        while queue:
            for _ in range(len(queue)):
                node, back = queue.pop(0)
                left = node - b
                right = node + a
                if (not back and left == x) or right == x:
                    return level + 1
                if left > 0 and left not in visited and left not in forbidden and not back:
                    visited.add(left)
                    queue.append((left, True))
                if right not in visited and right not in forbidden and right < 2000 + 2 * b:
                    queue.append((right, False))
            level += 1

        return -1
